home *** CD-ROM | disk | FTP | other *** search
- unit SimpleAssertFrm;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TForm1 = class(TForm)
- edtValue: TEdit;
- btnCalc: TButton;
- edtResult: TEdit;
- lblEquals: TLabel;
- procedure btnCalcClick(Sender: TObject);
- private
- procedure AssertValue(AValue: Extended);
- function CalcSquareRoot(AValue: Extended): Extended;
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
-
- { TForm1 }
-
- function TForm1.CalcSquareRoot(AValue: Extended): Extended;
- begin
- AssertValue(AValue);
- // Assert(AValue >= 0,'Pre-Condition failed: value must be >= 0');
- Result := Sqrt(AValue);
- end;
-
- procedure TForm1.btnCalcClick(Sender: TObject);
- var
- Value: Extended;
- begin
-
- try
- Value := StrToFloat(edtValue.Text);
- except
- on EConvertError do begin
- ShowMessage('Please enter a numerical value');
- Exit;
- end;
- end;
-
- if Value < 0 then begin
- ShowMessage('Square Root for a negative number is not defined!');
- end else begin
- edtResult.Text := FloatToStr(CalcSquareRoot(Value));
- end;
-
- end;
-
- procedure TForm1.AssertValue(AValue: Extended);
- begin
- Assert(AValue >= 0,'Pre-Condition failed: value must be >= 0');
- end;
-
- end.
-